<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <#include "/common/elibs.html">
</head><body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="${request.contextPath}/admin/haoge.html">首页</a>
        <a href="#">用户管理</a>
        <a>
          <cite>列表</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
      <i class="layui-icon" style="line-height:30px">ဂ</i></a>
  </div>
<div class="x-body">
    <div class="layui-row">
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm" lay-event="add" id="add" onclick="showMsg()">
                    <i class="layui-icon"></i>添加人员</button>
            </div>
        </script>
      <table class="layui-hide" id="test" lay-filter="test"></table>
      <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="updatePwd">修改密码</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="reset">重置密码</a>
      </script>
    </div>
  </div>
<script>
    isToken();
      layui.use('table', function() {
        var table = layui.table;
        table.render({
          elem: '#test'
          , url: path + '/pc/user/getUserInfoList'
            ,headers:{'X-USER-TOKEN':localStorage.getItem("token")}
          , toolbar: '#toolbarDemo'
          , title: '用户数据表'
          , cols: [[
            {type: 'checkbox', fixed: 'left'}
            , {field: 'userBaseInfoId', type: 'numbers', title: 'ID', width: 80, fixed: 'left'}
            , {field: 'nickName', title: '成员名称', width: 96}
            , {field: 'userPhone', title: '联系电话', width: 200}
            , {field: 'userPhone', title: '联系电话', width: 200}
            , {field: 'userAge', title: '成员年龄', width: 100}
            , {
              field: 'status', title: '当前状态', width: 100,
              templet: function (red) {
                if (red.status == '0') {
                  return "停用";
                } else if (red.status == '1') {
                  return "启用";
                } else if (red.status == '0') {
                  return "出现违规情况而被停用";
                }
              }
            }
            , {fixed: 'right', title: '操作', toolbar: '#barDemo'}
          ]]
          // ,statusCode: 200 //规定成功的状态码，默认：0
          /*,request: function(res){//数据填充自定义名称属性
              return {
                statusName: 'code', //规定数据状态的字段名称，默认：code
                statusCode: 200 //规定成功的状态码，默认：0
                , msgName: 'message' //规定状态信息的字段名称，默认：msg
                , countName: res.data.totalResult //规定数据总数的字段名称，默认：count
                , dataName: res.data.data //规定数据列表的字段名称，默认：data
              }
            }*/
          ,request: {
            pageName: 'currentPage' //页码的参数名称，默认：page
          }
          , parseData: function (res) { //res 即为原始返回的数据
            return {
              "code": res.code, //解析接口状态
              "msg": res.message, //解析提示文本
              "count": res.data.totalResult, //解析数据长度
              "data": res.data.data //解析数据列表
            }
          }
          , page: true
          , limit: 10
          , id: 'testReload'
        });
        var $ = layui.$, active = {
          reload: function () {
            var tcaParentsId = $("#tcaParentsId").val();
            var tcaName = $("#tcaName").val();
            if (tcaParentsId == "" && tcaName == "") {
              return;
            }
            table.reload('testReload', {
              where: { //设定异步数据接口的额外参数，任意设
                tcaParentsId: tcaParentsId
                , tcaName: tcaName
              }
              , page: {
                curr: 1 //重新从第 1 页开始
              }
            }); //重载表格
          }
        }
        $('#sreach').on('click', function () {
          var type = $(this).data('type');
          active[type] ? active[type].call(this) : '';
        });//监听行工具事件
        table.on('tool(test)', function (obj) {
          var data = obj.data;
          //console.log(obj)
          if (obj.event === 'del') {
            layer.confirm('真的删除行么', function (index) {
              var params = {
                "userBaseInfoId": data.userBaseInfoId
              }
              if (true) {
                  ajaxFun('post','/pc/user/deleteUser',params,function(data){
                      if (data.code != 0) {
                          alertFun(data);
                      } else {
                          $(".layui-form-checked").not('.header').parents('tr').remove();
                          layer.msg('删除成功', {icon: 1});
                          obj.del();
                          layer.close(index);
                          console.log("success !");
                      }
                  })
              }
            });
          } else if (obj.event === 'reset') {
            layer.confirm('真的重置行么', function (index) {
              var params = {
                "userBaseInfoId": data.userBaseInfoId
              }
              console.log(params);
              if (true) {
                  ajaxFun('post','/pc/user/resetUserPassword',params,function(data){
                      if (data.code != 0) {
                          alertFun(data);
                      } else {
                          layer.msg('重置成功', {icon: 1});
                          layer.close(index);
                          console.log("success !");
                      }
                  })
              }
            });
          } else if (obj.event === 'edit') {
            window.location.href = '${request.contextPath}/modules/users/edit.html?id=' + obj.data.userBaseInfoId;
          } else if (obj.event === 'updatePwd') {
            window.location.href = '${request.contextPath}/modules/users/updatePwd.html?id=' + obj.data.userBaseInfoId;
          }
        });
      });
    </script></body></html>

<script>
        function showMsg() {
            window.location.href=path+"/modules/users/add.html";
        }
</script>